import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/core/values/colors.dart';
import 'package:enterprise_v6_app/app/core/values/gaps.dart';
import 'package:enterprise_v6_app/app/modules/application/double_prevention_page/risk_control_page/risk_security_identification_page/risk_unit_details/risk_unit_details_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class RiskUnitDetailsPage extends StatelessWidget {
  RiskUnitDetailsPage({super.key});

  final controller = Get.put(RiskUnitDetailsController());
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.bg_color_grey,
      appBar: CustomAppBar(
        titleText: '详情',
      ),
      body: GetBuilder(
          init: controller,
          builder: (_) {
            return SingleChildScrollView(
              child: Column(
                children: [
                  _titleBg(),
                  Container(
                    height: 40.w,
                    width: double.infinity,
                    color: const Color(0xFFF4F7FF),
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.only(left: 40.w),
                    child: Text(
                      '风险分析单元名称：${controller.data?.riskUnitName??''}',
                      style: TextStyle(
                        fontSize: 16.sp,
                      ),
                    ),
                  ),
                  Container(
                    height: 1.w,
                    color: const Color(0xFFDEE5FD),
                  ),
                  Container(
                    height: 50.w,
                    color: Colors.white,
                    child: Row(
                      children: [
                        Expanded(child: _title('责任部门:', controller.data?.hazardDep??'')),
                        Expanded(child: _title('责任人:', controller.data?.hazardLiablePerson??'')),
                      ],
                    ),
                  ),
                  _titleBg(),
                  Container(
                    color: Colors.white,
                    padding: EdgeInsets.symmetric(horizontal: 40.w, vertical: 14.w),
                    child: Column(
                      children: [
                        _getTextView(
                          title: '风险分析单元辨识部门：',
                          value: controller.data?.hazardDistinguishDep??'',
                        ),
                        AppGaps.vGap12,
                        _getTextView(
                          title: '风险分析单元辨识人：',
                          value: controller.data?.hazardDistinguishPerson??'',
                        ),
                        AppGaps.vGap12,
                        _getTextView(
                          title: '创建人：',
                          value: controller.data?.createBy??'',
                        ),
                        AppGaps.vGap12,
                        _getTextView(
                          title: '创建时间：',
                          value: controller.data?.createDate??'',
                        ),
                        AppGaps.vGap12,
                        _getTextView(
                          title: '最后修改人：',
                          value: controller.data?.updateBy??'',
                        ),
                        AppGaps.vGap12,
                        _getTextView(
                          title: '最后修改时间：',
                          value: controller.data?.updateDate??'',
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            );
          }),
    );
  }

  Widget _title(String title, String? value) {
    return Container(
      padding: EdgeInsets.only(top: 8.w, bottom: 8.w),
      child: Row(
        children: [
          AppGaps.hGap40,
          Text(
            title,
            style: TextStyle(
              color: Colors.black,
              fontSize: 12.sp,
            ),
          ),
          AppGaps.hGap12,
          if (value != null)
           Expanded(child:  Text(
             value,
             style: TextStyle(
               color: const Color(0xFF7C7D93),
               fontSize: 12.sp,
             ),
           ),)
        ],
      ),
    );
  }


  /// 标题背景分隔栏
  Widget _titleBg() {
    return Column(
      children: [
        AppGaps.vGap12,
        Container(
          height: 2.w,
          color: const Color(0xFF587DF5),
        ),
      ],
    );
  }

  /// 获取字段显示
  Widget _getTextView({required String title, required String value, double? width}) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        SizedBox(
          width: width ?? 150.w,
          child: Text(
            title,
            style: TextStyle(
              fontSize: 13.sp,
              height: 1.2,
              fontWeight: FontWeight.w400,
              color: Colors.black,
            ),
          ),
        ),
        Expanded(
            child: Text(
          value,
          style: TextStyle(
            fontSize: 14.sp,
            height: 1.2,
            fontWeight: FontWeight.w400,
            color: const Color(0xFF7C7D93),
          ),
        ))
      ],
    );
  }
}
